<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float:left">
    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
      >
        <el-table-column align="center" prop="live_id" label="直播号" width="70" :fixed="isMobile()?'left':undefined" />
        <el-table-column align="center" prop="live_name" label="直播名" width="120">
          <template slot-scope="scope">
            <el-input v-model="scope.row.live_name" @change="change_status(scope.row.live_id,'live_name' ,scope.row.live_name)"></el-input>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="live_picture" label="封面" >
          <template slot-scope="scope">
            <pre-view :src="scope.row.live_picture" width="50px" height="50px"/>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="live_picture_h" label="横版" >
          <template slot-scope="scope">
            <pre-view :src="scope.row.live_picture_h" width="85px" height="50px"/>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="live_picture_h" label="上传" >
          <template slot-scope="scope">
            <el-button
              :type="'primary'"
              size="mini"
              @click="open(scope.row)"
            >上传</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="user_info.nickname" label="用户名"  />
        <el-table-column align="center" prop="concern" label="关注人数" width="120">
          <template slot-scope="scope">
            <el-input v-model="scope.row.concern" @change="change_status(scope.row.live_id,'concern' ,scope.row.concern)"></el-input>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="zan" label="点赞人数" width="120">
          <template slot-scope="scope">
            <el-input v-model="scope.row.zan"  @change="change_status(scope.row.live_id,'zan' ,scope.row.zan)"></el-input>
          </template>
        </el-table-column>
       <el-table-column align="center" prop="num" label="虚拟人数设置" width="120">
          <template slot-scope="scope">
            <el-input v-model="scope.row.num" @change="change_status(scope.row.live_id,'num' ,scope.row.num)"></el-input>
          </template>
        </el-table-column>
         <el-table-column align="center" prop="sort" label="排序" width="120">
          <template slot-scope="scope">
            <el-input v-model="scope.row.sort" @change="change_status(scope.row.live_id,'sort' ,scope.row.sort)"></el-input>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="online" label="直播间真实人数">
          <template slot-scope="scope">{{scope.row.online-scope.row.num}}</template>
        </el-table-column>
         <el-table-column align="center" prop="status" label="直播状态" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status >0" type="success">直播中</el-tag>
            <el-tag v-else >已结束</el-tag>
          </template>
        </el-table-column>
       <el-table-column align="center" prop="cat_id" label="直播分类" width="120">
         <template slot-scope="scope">
         <el-select v-model="scope.row.cat_id" @change="change_cat(scope.row.live_id,scope.row.cat_id)" placeholder="请选择">
          <el-option
            v-for="item in cate"
            :key="item.id"
            :label="item.title"
            :value="item.id">
          </el-option>
        </el-select>
        </template>
      </el-table-column>

        <el-table-column align="center" prop="is_lock" label="冻结" width="80">
          <template slot-scope="scope">
            <el-button
              :type="scope.row.is_lock === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.live_id,'is_lock' ,scope.row.is_lock == 1 ? 0: 1)"
            >{{ scope.row.is_lock === 1 ? "是" : "否" }}</el-button>
          </template>
        </el-table-column>
         <el-table-column align="center" prop="is_top" label="置顶" width="80">
          <template slot-scope="scope">
            <el-button
            
              :type="scope.row.is_top === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.live_id,'is_top' ,scope.row.is_top == 1 ? 0: 1)"
            >{{ scope.row.is_top === 1 ? "是" : "否" }}</el-button>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="create_time" label="创建时间"  />
        <el-table-column align="center" prop="end_time" label="结束时间"  />
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <drawer title="上传封面" :isShow="update_visible"  @update:isShow="update_visible=false" width=".3" >
      <el-form ref="form" :model="form" label-width="150px" class="layout-all " :label-position="isMobile()?'top':'left'">
      <el-form-item label="封面:" prop="live_picture">
        <upload-pic v-if="live_list_single==2" :thumb="form.live_picture" @update:thumb="form.live_picture=$event" width="100" height="150" :append="true"/>
        <upload-pic v-else :thumb="form.live_picture" @update:thumb="form.live_picture=$event" width="100" :append="true"/>
      </el-form-item>

      <el-form-item label="横版" prop="live_picture_h">
        <upload-pic :thumb="form.live_picture_h" @update:thumb="form.live_picture_h=$event" width="175" height="100" :append="true"/>
      </el-form-item>
      </el-form>

            <el-button @click="update_visible = false">取 消</el-button>
            <el-button type="primary" @click="update()"
              >确 定</el-button
            >
    
    </drawer>
  </div>
</template>

<script>
import control from '../../components/control/control'
export default {
  name:'live_index',
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入直播名或编号', field: 'title', val: '' }
      ],
      value: '',
      update_visible: false,
      live_list_single: 0,
      form: [],
      searchWhere: {
        title: ''
      },
      save_zan:0,
      tableData: [],
      cate: [],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },
  activated(){
    if(this.$getUpdate()){
      this.onSearch()
    }
  },
  created() {
    this.onSearch()
  },
  methods: {
    update(){
      console.log(this.form)
      this.get('/admin/Live/save_img', this.form, 'POST').then(e => {
        this.onSearch()
      })
    },
    open(row){
      this.form={
        live_id:row.live_id,
        live_picture:row.live_picture,
        live_picture_h:row.live_picture_h
      }
      this.update_visible=true
    },
    change_cat(live_id,cat_id){
      let form={
        id:live_id,
        field:'cat_id',
        val:cat_id,
      }
      this.get('/admin/Live/update' , form, 'POST').then(e => {
           this.$message({
            message: '修改成功',
            type: 'success'
          });
      })

      console.log(value)
    },
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      this.get('/admin/Live/index', form, 'POST').then(e => {
        console.log(e)
        this.tableData = e.list.data
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.current_page = e.list.current_page
        this.cate = e.cate
        this.live_list_single = e.live_list_single
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 修改状态
    change_status(id, field, val) {
      
      const form = {
        id:id,
        field:field,
        val:val,
      }
      this.get('/admin/Live/update' , form, 'POST').then(e => {
           this.$message({
            message: '修改成功',
            type: 'success'
          });
          this.onSearch()
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
